<?php
namespace app\api\controller;
/**
 * @Author: user
 * @Date:   2019-04-03 19:50:59
 * @Last Modified by:   user
 * @Last Modified time: 2019-04-07 12:22:47
 */
use think\Controller;
use app\api\model\ApiLoginModel;
/**
 * 
 */
class ApiLoginController extends Controller
{
	public function doLogin()
	{
		if(!$this->request->isPost()){
			return zy_json(false,'请求类型错误！');
		}
		$data=$this->request->param();
		if(!isset($data['username']) && empty($data['username'])){
			return zy_json(false,'nouser');
		}
		if(!isset($data['password']) && empty($data['password'])){
			return zy_json(false,'nopass');
		} 
		$data['username']=base64_decode($data['username']);
		$data['password']=base64_decode($data['password']);
		//验证
		$login=new ApiLoginModel();
		$res=$login->doLogin($data);
		$res=json_decode($res,true);
		if($res['status']=='success'){
			//登入成功返回首次登入子系统所需基础信息
			$info=$login->getBaseInfo($res['data']['id']);
			return zy_json(true,'',$info);
		}else{
			//返回错误信息
			return  zy_json(false,$res['message']);
		}
	}
	/**
	 * 变更激活状态
	 */
	public  function updateActiveStatus()
	{
		if(!$this->request->isPost()){
			return zy_json(false,'请求类型错误！');
		}
		$data=$this->request->param();
		if(!isset($data['username']) && empty($data['username'])){
			return zy_json(false,'nouser');
		}
		if(!isset($data['password']) && empty($data['password'])){
			return zy_json(false,'nopass');
		} 
		$data['username']=base64_decode($data['username']);
		$data['password']=base64_decode($data['password']);
		//验证
		$login=new ApiLoginModel();
		$res=$login->updateActiveStatus($data);
		return $res;
	}
}